﻿using B.S.BasicData.Api.Write.Application.Command.Approval;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 请假服务
    /// </summary>
    [Route("api/[controller][action]")]
    [ApiController]
    [Authorize]
    public class ApprovalController : ControllerBase
    {
        IMediator _mediator;

        public ApprovalController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 添加请假申请单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<ApiResult<int>> CreateApproval(CreateApprovalCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 申请删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public Task<ApiResult<int>> DeleteApproval([FromQuery] DeleteApprovalCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 申请单修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateApproval(UpdateApprovalCommand request)
        {
            return _mediator.Send(request);
        }
    }
}
